package com.lineage.data.item_etcitem;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.sql.CharItemsTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_HPUpdate;
import com.lineage.server.serverpackets.S_ItemStatus;
import com.lineage.server.serverpackets.S_MPUpdate;
import com.lineage.server.serverpackets.S_OwnCharStatus;
import com.lineage.server.serverpackets.S_SPMR;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.william.drop_type_weapon_clean2;
import com.lineage.william.drop_type_weapon_item2;

public class GmWeapon_Color1 extends ItemExecutor {
  private int type1;
  
  public static ItemExecutor get() {
    return new GmWeapon_Color1();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targObjId = data[0];
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (tgItem == null)
      return; 
    if (!tgItem.getItem().isdropcolor()) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("似乎没发生什么事情。"));
      return;
    } 
    if (tgItem.getItem().getUseType() != 1) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("似乎没发生什么事情。"));
      return;
    } 
    if (tgItem.getItemArmorType() == this.type1) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("似乎没发生什么事情。"));
      return;
    } 
    if (tgItem.getItemArmorType() > 0) {
      drop_type_weapon_clean2.forIntensifyArmor(pc, tgItem);
      tgItem.setItemArmorType(this.type1);
      CharItemsTable charItemsTable = new CharItemsTable();
      try {
        charItemsTable.updateItemArmorType(tgItem);
      } catch (Exception e) {
        e.printStackTrace();
      } 
      drop_type_weapon_item2.forIntensifyArmor(pc, tgItem);
      pc.getInventory().removeItem(item, 1L);
      pc.sendPackets((ServerBasePacket)new S_ItemStatus(tgItem));
      pc.sendPackets((ServerBasePacket)new S_SPMR(pc));
      pc.sendPackets((ServerBasePacket)new S_OwnCharStatus(pc));
      pc.sendPackets((ServerBasePacket)new S_HPUpdate(pc.getCurrentHp(), pc.getMaxHp()));
      pc.sendPackets((ServerBasePacket)new S_MPUpdate(pc.getCurrentMp(), pc.getMaxMp()));
      return;
    } 
    tgItem.setItemArmorType(this.type1);
    CharItemsTable cit = new CharItemsTable();
    try {
      cit.updateItemArmorType(tgItem);
    } catch (Exception e) {
      e.printStackTrace();
    } 
    drop_type_weapon_item2.forIntensifyArmor(pc, tgItem);
    pc.getInventory().removeItem(item, 1L);
    pc.sendPackets((ServerBasePacket)new S_ItemStatus(tgItem));
    pc.sendPackets((ServerBasePacket)new S_SPMR(pc));
    pc.sendPackets((ServerBasePacket)new S_OwnCharStatus(pc));
    pc.sendPackets((ServerBasePacket)new S_HPUpdate(pc.getCurrentHp(), pc.getMaxHp()));
    pc.sendPackets((ServerBasePacket)new S_MPUpdate(pc.getCurrentMp(), pc.getMaxMp()));
  }
  
  public void set_set(String[] set) {
    try {
      this.type1 = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
  }
}
